<template>
  <div class="tui_img">
    <!-- 头部导航栏 -->
    <head-component
      :rightClick="rightClick"
      :rightWords="rightWords"
      :title="name"/>
    <!-- 内容部分 -->
    <div class="tui_img_box">
      <img :src="shareImg" alt="">
    </div>
  </div>
</template>
<script>
import headComponent from '@/components/layout/head'
export default {
  name: '',
  components: {
    headComponent
  },
  data() {
    return {
      id:　this.$route.query.id - 0,
      name:　this.$route.query.name,
      rightWords: '保存',
      shareImg: ''
    }
  },
  watch: {},
  mounted() {
    this.getNews();
  },
  methods: {
    // 获取页面初始信息
    getNews(){
      let $this = this;
      var t = $this.$toast.loading({message:'正在加载数据',mask:true, duration:9999})
      var data = {u_id: localStorage.getItem('uid'), token:localStorage.getItem('token'),p_id:$this.id};
      $this.$axios.post('/index.php?m=index&c=pro_detail',data)
        .then((res) => {
          t.clear();
          if(res.data.code == 1){
            $this.shareImg = res.data.share;
          }else{
            $this.$toast({
              message: res.data.msg,
              duration: 800
            })
          }
        })
    },
    rightClick(){
      let $this = this;
      var task = window.plus.downloader.createDownload($this.shareImg, {}, function (file, status) {
        if (status == 200) {
          window.plus.gallery.save(file.filename, function () {
            $this.$toast({
              message: '保存成功',
              duration: 1000
            })
            // layer.open({ skin: 'msg', time: 1, content: '保存成功' });
          }, function () {
            $this.$toast({
              message: '保存失败',
              duration: 1000
            })
            // layer.open({ skin: 'msg', time: 1, content: '保存失败' });
          });
        }
      });
      task.start();
    }
  },
}
</script>
<style lang="less">
  .tui_img_box{
    margin-top: 1.2rem;
    border-top: 1Px solid #f5f5f5;
    padding:0.5rem 0.5rem 0;
    img{ width: 100%; }
  }
</style>
